package com.leetcode;

import java.util.*;

public class Test_1 {
    public static void main(String[] args) {
        HashSet<Object> set = new HashSet<>();
        set.add(1);
        set.add(2);
        set.add(3);
        set.add(4);

        ArrayList<Object> arr = new ArrayList<>();
        Iterator iterator=set.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            arr.add(next);
        }

        for (Object o :arr) {
            System.out.println(o);
        }
    }
}

//三数之和
class Solution {
    public List<List<Integer>> threeSum(int[] nums) {
        int n=nums.length;
        Arrays.sort(nums);
        List<List<Integer>> ret=new ArrayList<>();
        for(int i=0;i<n;){
            int left=i+1;
            int right=n-1;
            int tem=-nums[i];
            if(nums[i]>0)break;
            while(left<right){
                int sum=nums[left]+nums[right];
                if(sum>tem)right--;
                else if(sum<tem)left++;
                else{//相等
                    ret.add(new ArrayList<Integer>(Arrays.asList(nums[i], nums[left], nums[right])));
                    left++;
                    right--;//去重
                    while(left<right&&nums[left]==nums[left-1])left++;
                    while(left<right&&nums[right]==nums[right+1])right--;
                }
            }
            i++;
            while(i<n&&nums[i]==nums[i-1])i++;
        }
        return ret;
    }
}
